home *** CD-ROM | disk | FTP | other *** search
/ com!online 2002 July / com!online0702.iso / software / livemotion / DATA1.CAB / Scripting_Resources / Samples / Automation_Scripts / Fast Character Animation.js < prev    next >
Encoding:
Text File  |  2002-05-13  |  6.0 KB  |  163 lines

  1. //////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED 
  4. // Copyright 2002 Adobe Systems Incorporated 
  5. // All Rights Reserved 
  6. //
  7. // NOTICE:  Adobe permits you to use, modify, and 
  8. // distribute this file in accordance with the terms
  9. // of the Adobe license agreement accompanying it.  
  10. // If you have received this file from a source 
  11. // other than Adobe, then your use, modification,
  12. // or distribution of it requires the prior 
  13. // written permission of Adobe. 
  14. //
  15. //////////////////////////////////////////////////
  16.  
  17. //////////////////////////////////////////////////
  18. // Fast Character Animation.js
  19. // 
  20. // DESCRIPTION
  21. //
  22. // This script takes the selected text object and breaks it
  23. // into individual character objects and animates the appearance
  24. // of characters in a sequence. It also changes background to a single
  25. // color and the text color to a single color.
  26. //
  27. // HOW TO USE
  28. //
  29. // Create any Text object and select it in the Composition.
  30. // Select Automation > Run Automation Script > Fast Character Animation.js
  31. // 
  32. // You can view the animation in Preview or Export the file
  33. // and view the html in the browser.
  34. // 
  35. //////////////////////////////////////////////////
  36.  
  37. // Main Code [Execution of script begins from here]
  38.  
  39. // Check if any composition is open
  40. if(application.compositions.length > 0){
  41.     comp = application.currentComposition;
  42.     if(comp.selection.length >= 1){// Checks if at least one object is selected 
  43.         var selected = comp.selection; // Currently selected objects
  44.         var objects = new Array(); // An array to store individual characters 
  45.         // Breaks the text object into individual characters and assign to the array objects.
  46.         objects = selected[0].convertIntoObjects(); 
  47.         application.currentComposition.saveSelection(); // Saves the current selection
  48.         
  49.         animate(objects, 3, 20, 100);// Call function animate to animate the characters
  50.         // You can make changes in the parameters here to call function with different
  51.         // values
  52.         
  53.         application.currentComposition.restoreSelection(); // Restores the saved selection
  54.     }
  55.     else{ // Brings up the console window 
  56.         Console.show();
  57.         // Writes the requirement to the console
  58.         Console.write("\nPlease create and select at least one text object to apply charater animation and run the script again.\n");    
  59.     }
  60. }
  61. else{// if no composition open
  62.     // opens a new composition
  63.     comp = application.newComposition();
  64.     Console.show();
  65.     Console.write("New Composition opened\nPlease create and select at least one text object to apply charater animation and run the script again.\n");
  66. }
  67.  
  68. // Setting the start color of the background color sets background to a single color
  69. // Setting color to black here so r=0, g=0 and b=0;
  70. comp.backgroundColorGradient.startColor.red = 0;
  71. comp.backgroundColorGradient.startColor.green = 0;
  72. comp.backgroundColorGradient.startColor.blue = 0;
  73.  
  74.  
  75.  
  76. // Add your own functions here
  77.  
  78. //////////////////////////////////////////////////
  79. // 
  80. // animate:
  81. // Animates the appearance of the individual character 
  82. // objects.
  83. //
  84. // Each object is kept invisible for a limited amout 
  85. // of time/frames. Object 1 is invisible for first 3 
  86. // frames, object 2 is invisible for first 6 frames
  87. // and so on...And then they all appear gradually.
  88. // 
  89. // object_Array:   The array of characters to be animated
  90. // keyFrameRate:   The frame at which the opacity of the 
  91. //                 object changes.
  92. // incrementValue: The amount of opacity increased gradually.
  93. // finalOpacity:   The final maximum opacity to be given to 
  94. //                 the object.
  95. //
  96. //////////////////////////////////////////////////
  97.  
  98. function animate(object_Array, keyFrameRate, incrementValue, finalOpacity){
  99.     var oriOpacity=0; // Variable to store original/start opacity of the object
  100.     var frame0; // Variable to store start frame of each object
  101.     var f; // Variable for the frame number
  102.     var end; // Variable for end of invisibility of characters
  103.     var objOpacity; // Variable to store opacity of object for comparison
  104.     
  105.     // Loop to make all objects invisible and change their color to green    
  106.     for(i=0 ; i < object_Array.length ; i++){
  107.         
  108.         // Setting objects start color to a single color - green. 
  109.         object_Array[i].layers[0].colorGradient.startColor.red = 31;
  110.         object_Array[i].layers[0].colorGradient.startColor.green = 255;
  111.         object_Array[i].layers[0].colorGradient.startColor.blue = 60;
  112.     
  113.         // To make all characters invisible changing their opacity to 0.
  114.         object_Array[i].opacity = 0;
  115.     }
  116.     
  117.     // Loop to stagger appearance of all objects first and then make them 
  118.     // visible gradually
  119.     for(i=0 ; i < object_Array.length ; i++){
  120.         
  121.         // Start all objects animation at the same frame/time
  122.         frame0 = object_Array[i].startFrame; 
  123.                 
  124.         // Start the stopwatch for opacity
  125.         object_Array[i].stopwatch.opacity = true;
  126.         
  127.         // Since starting does not record the attribute assign it again 
  128.         // to record it's value
  129.         object_Array[i].opacity = oriOpacity ;
  130.         
  131.         // Objects are invisible for end frames i.e. 3 for object 1, 
  132.         // 6 for object 2 and so on respectively
  133.         // The formula used to caluclate end time is:
  134.         // (i+1) * keyFrameRate = 1*3 = 3 for object i (object 1)
  135.         // (i+1) * keyFrameRate = 2*3 = 6 for object i (object 2)
  136.         end = (i+1)*keyFrameRate; 
  137.         
  138.         // Assigning current opacity of object to objOpacity for 
  139.         // comparison
  140.         objOpacity = object_Array[i].opacity;
  141.         
  142.         // Loop to set opacity 0 through frames for each object's 
  143.         // invisibility time.
  144.         // Gradually increase their opacity to complete visibility
  145.         // Begin with the first frame 0 
  146.         for( f=0 ; objOpacity < finalOpacity; f+=keyFrameRate){
  147.             // Set the key frame at the current frame
  148.             object_Array[i].currentFrame = frame0 + f;
  149.             
  150.             // Check the frame number and keep it invisible/visible
  151.             if(f <= end){
  152.                 object_Array[i].opacity = 0;
  153.             }
  154.             else{
  155.                 object_Array[i].opacity = objOpacity + incrementValue;
  156.             }
  157.             
  158.             // Assign opacity to objOpacity for comparison
  159.             objOpacity = object_Array[i].opacity;
  160.         }
  161.     }
  162. }    
  163.